package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.MarketFeedback;

import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.service.wx.WXFeedbackService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import com.cskaoyan.exception.MarketValidationException;
import com.cskaoyan.service.wx.WXFeedbackService;
import com.cskaoyan.util.ValidationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Yan Dexuan
 * @since 2022/06/29 10:21
 */

@RestController
@RequestMapping("wx/feedback")
public class WXFeedbackController {

    @Autowired
    WXFeedbackService wxFeedbackService;

    /**
     * 添加用户意见反馈。
     * 增加正则验证
     * @param marketFeedback
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author Yan Dexuan
     * @since 2022/06/29 11:14
     */
    @RequestMapping("submit")
    public BaseRespVo feedbackSubmit(@Validated @RequestBody MarketFeedback marketFeedback, BindingResult bindingResult) throws MarketValidationException {
        ValidationUtils.valid(bindingResult);
        Integer integer = wxFeedbackService.feedbackSubmit(marketFeedback);

        if (integer > 0) {
            return BaseRespVo.ok();
        }

        return BaseRespVo.invalidData();
    }

}
